//
//  BaseLabel.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/3.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "BaseLabel.h"
#import "MJMacro.h"
@implementation BaseLabel
-(void)alignTop
{
    // 对应字号的字体一行显示所占宽高
    CGSize fontSize = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}];
    // 多行所占 height*line
    double height = fontSize.height * self.numberOfLines;
    // 显示范围实际宽度
    double width = self.frame.size.width;
    // 对应字号的内容实际所占范围
    CGSize stringSize = [self.text boundingRectWithSize:CGSizeMake(width, height) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:self.font} context:nil].size;
    // 剩余空行
    NSInteger line = (height - stringSize.height) / fontSize.height;
    // 用回车补齐
    for (int i = 0; i < line; i++) {
        
        self.text = [self.text stringByAppendingString:@"\n "];
    }
  
}
-(void)alignBottom
{
    CGSize fontSize = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}];
    NSLog(@"%f", fontSize.height);
    double height = fontSize.height * self.numberOfLines;
    NSLog(@"%ld", self.numberOfLines);
    double width = self.frame.size.width;
    CGSize stringSize = [self.text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.font} context:nil].size;
    NSLog(@"stringSize%f", stringSize.width);
    NSLog(@"stringSize%f", stringSize.height);
    NSInteger line = self.bounds.size.height / fontSize.height;
    NSLog(@"%ld", line);
    // 前面补齐换行符
    for (int i = 0; i < line - 6; i++) {
        self.text = [NSString stringWithFormat:@" \n%@", self.text];
    }
      NSLog(@"%@", [NSString stringWithFormat:@"%@/", self.text]);
}
- (instancetype)init{
    self = [super init];
    if (IS_IPHONE_5) {
        self.font = [UIFont systemFontOfSize:self.font.pointSize - 4
                     ];
    }
    if (IS_IPHONE_6) {
        self.font = [UIFont systemFontOfSize:self.font.pointSize - 2];
    }

    return self;
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        if (IS_IPHONE_5) {
            self.font = [UIFont systemFontOfSize:self.font.pointSize - 4
                         ];
        }
        if (IS_IPHONE_6) {
            self.font = [UIFont systemFontOfSize:self.font.pointSize - 2];
        }

    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        if (IS_IPHONE_5) {
            self.font = [UIFont systemFontOfSize:self.font.pointSize - 4
                         ];
        }
        if (IS_IPHONE_6) {
            self.font = [UIFont systemFontOfSize:self.font.pointSize - 2];
        }
        
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
